#include "LinkedStack.h"

void LinkeStackInit(StackNode* pt)
{
	assert(pt);
	pt->next = nullptr;
}

void LinkeStackDestroy(StackNode* pt)
{
	assert(pt);
	StackNode* tmp = pt;
	while (tmp)
	{
		StackNode* des = tmp;
		tmp = tmp->next;
		free(des);
	}
}

void LinkeStackPush(StackNode* pt, StackDate x)
{
	assert(pt);
	StackNode* newnode = (StackNode*)malloc(sizeof(StackNode));
	assert(newnode);
	newnode->x = x;

	StackNode* tmp = pt;
	while (tmp->next)
	{
		tmp = tmp->next;
	}
	tmp->next = newnode;
	newnode->next = nullptr;
}

StackDate LinkeStackPop(StackNode* pt)
{
	assert(pt && pt->next);
	StackNode* tmp = pt->next;
	pt->next = tmp->next;
	StackDate x = tmp->x;
	free(tmp);
	return x;
}

bool LinkeStackDetect(StackNode* pt)
{
	assert(pt);
	return pt->next;
}
